package top.ajunnihao.core.util.resp;

import org.springframework.http.HttpStatus;

/**
 * TODO 响应数据基类
 *
 * @author AJun
 * @version 1.0.0
 * @date 2020/5/15
 */
public class BaseResp {

    /**
     * HTTP 状态码
     */
    private Integer status;

    /**
     * 是否成功
     */
    private Boolean success;

    /**
     * 响应消息
     */
    private String msg;

    /**
     * 附加响应消息
     */
    private String message;

    protected BaseResp() {

    }

    protected BaseResp(CodeEnum codeEnum) {
        this.success = codeEnum.getSuccess();
        this.msg = codeEnum.getMsg();
    }

    protected BaseResp(CodeEnum codeEnum, String message) {
        this.success = codeEnum.getSuccess();
        this.msg = codeEnum.getMsg();
        this.message = message;
    }

    protected BaseResp(CodeEnum codeEnum, HttpStatus httpStatus) {
        this.status = httpStatus.value();
        this.success = codeEnum.getSuccess();
        this.msg = codeEnum.getMsg();
    }

    protected BaseResp(CodeEnum codeEnum, Integer statusCode) {
        this.status = HttpStatus.valueOf(statusCode).value();
        this.success = codeEnum.getSuccess();
        this.msg = codeEnum.getMsg();
    }

    protected BaseResp(CodeEnum codeEnum, HttpStatus httpStatus, String message) {
        this.status = httpStatus.value();
        this.success = codeEnum.getSuccess();
        this.msg = codeEnum.getMsg();
        this.message = message;
    }

    protected BaseResp(CodeEnum codeEnum, Integer statusCode, String message) {
        this.status = HttpStatus.valueOf(statusCode).value();
        this.success = codeEnum.getSuccess();
        this.msg = codeEnum.getMsg();
        this.message = message;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public Boolean getSuccess() {
        return success;
    }

    public void setSuccess(Boolean success) {
        this.success = success;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    @Override
    public String toString() {
        return "BaseResp{" +
                "status=" + status +
                ", success=" + success +
                ", msg='" + msg + '\'' +
                ", message='" + message + '\'' +
                '}';
    }

}
